/**************************************************
** REPLICATION FILE FOR 
**
** Marsh, Michael and Slava Mikhaylov 
** "Economic voting in a crisis: The Irish election
** of 2011" Electoral Studies, 2012, forthcoming
**
** doi:10.1016/j.electstud.2012.02.010
**************************************************/


use estimation_file, clear

tsset ym

keep if tin(,2011m2)

/* Bank Guarantee Sep 30 2008*/
gen bankguarantee=0 if tin(,2008m10)
recode bankguarantee .=1 if tin(2008m11,)

/* Bank Guarantee Sep 30 2010*/
gen bondmarket=0 if tin(,2010m10)
recode bondmarket .=1 if tin(2010m11,)

* IMF
gen IMF=0 if tin(,2010m11)
recode IMF .=1 if tin(2010m12,)

/* Election 2007*/
/* Election 2011*/
generate e07=0 if tin(,2007m5)
replace e07=1 if tin(2007m6,)
generate e11=0 if tin(,2011m2)
replace e11=1 if tin(2011m3,)

/*Time*/
gen time =_n

/*Post-treatment*/

egen postBG=seq() if tin(2008m11,)
recode postBG .=0

egen postBond=seq() if tin(2010m11,)
recode postBond .=0


/********************
***    ESTIMATION ***
********************/


/*MAIN MODEL*/
reg iff time bankguarantee postBG bondmarket /// 
postBond, vce(robust)

est store model1

outreg2 [model1] using treatment, replace /// 
stats(coef se) /// 
adjr2 auto(3) excel



/*ADDING ECONOMIC VARIABLES*/

reg iff time bankguarantee postBG bondmarket postBond /// 
inflation  ///
, vce(robust)

est store model2

reg iff time bankguarantee postBG bondmarket postBond /// 
unemp  ///
, vce(robust)

est store model3

reg iff time bankguarantee postBG bondmarket postBond /// 
iip ///
, vce(robust)

est store model4

reg iff time bankguarantee postBG bondmarket postBond /// 
i_cci  ///
, vce(robust)

est store model5

reg iff time bankguarantee postBG bondmarket postBond /// 
i_cci inflation unemp iip ///
, vce(robust)

est store model6


outreg2 [model2 model3 model4 model5 model6] /// 
using econ, replace stats(coef se) /// 
adjr2 auto(3) excel




/*Newey-West*/

newey iff time bankguarantee postBG bondmarket postBond, lag(3)

est store newey1

test bankguarantee bondmarket

newey iff bankguarantee bondmarket /// 
inflation , lag(3)

est store newey2

test bankguarantee bondmarket

newey iff bankguarantee bondmarket /// 
unemp , lag(3) 

est store newey3

test bankguarantee bondmarket

newey iff bankguarantee bondmarket /// 
iip , lag(3)

est store newey4

test bankguarantee bondmarket

newey iff bankguarantee bondmarket /// 
i_cci  , lag(3)

est store newey5

test bankguarantee bondmarket

newey iff bankguarantee bondmarket /// 
i_cci inflation unemp iip , lag(3)

est store newey6

test bankguarantee bondmarket



outreg2 [newey1 newey2 newey3 newey4 newey5 newey6] /// 
using newey, replace stats(coef se) e(F) /// 
dec(3) excel




/* TESTING CONSUMER CONFIDENCE*/

newey i_cci bankguarantee bondmarket /// 
 inflation unemp iip , lag(3)

test bankguarantee bondmarket


/**  TESTING SERIAL CORRELATION   **/


reg iff time bankguarantee postBG bondmarket postBond

estat bgodfrey, lags(3)
estat dwatson




/***************************
***       GRAPHS         ***
***************************/

/*Figure 1*/

preserve

use polls, clear
keep if survey=="Red"
tsset ddate

twoway (scatter ff ddate, mcolor(black) msize(small)) /// 
, ytitle("FF popularity") yscale(nofextend) ///
ttitle("") ylabel(10(10)30 42, labsize(small)) ///  
tscale(nofextend) /// 
graphregion(fcolor(white) lcolor(white)) legend(off) /// 
tline( 24may2007 30sep2008 30sep2010, lwidth(vvthin) lc(black)) ///
tlabel(minmax 24may2007 30sep2008 30sep2010, labsize(small) /// 
angle(45)) 

restore


/*Figure 2*/
twoway (line i_cci ym) /// 
(line inflation ym, yaxis(2)) /// 
(line unemployment ym, yaxis(3)) /// 
(line iip ym, yaxis(4)) /// 
, yscale(off) yscale(off axis(2)) /// 
yscale(off axis(3)) yscale(off axis(4)) /// 
tscale(nofextend) /// 
graphregion(fcolor(white) lcolor(white))  /// 
tline( 2007m5 2008m9 2010m9, lwidth(vthin) lc(black)) ///
tlabel(minmax 2007m5 2008m9 2010m9, angle(45)) ///
ttitle("") scheme(s2mono) ///  
graphregion(margin(t+3 l+5 r+5)) /// 
legend(order(1 "Consumer confidence" 2 "Inflation" /// 
3 "Unemployment" 4 "Industrial Production") cols(1) /// 
region(lcolor(white)))




/*Figure 3*/

twoway (line i_cci ym, sort lcolor(black) lw(thick)) /// 
(line iff ym, sort yaxis(2) lcolor(black) lp(dash) /// 
lw(thick)), ytitle("Consumer confidence index", /// 
size(small)) yscale(nofextend) ///
ttitle("") ylabel(minmax -10, format(%12.0f) /// 
labgap(medsmall) labsize(small)) /// 
ylabel(minmax 25 35, axis(2) labsize(small)) /// 
ytitle("FF popularity", axis(2) /// 
size(small)) tscale(nofextend) /// 
graphregion(fcolor(white) lcolor(white)) legend(off) /// 
tline( 2007m5 2008m9 2010m9, lwidth(vthin) lc(black)) ///
tlabel(minmax 2007m5 2008m9 2010m9, labsize(small) /// 
angle(45)) yscale(nofextend axis(2))

graph save "i_cci", replace


twoway (line unemp ym, sort lcolor(black) lw(thick)) /// 
(line iff ym, sort yaxis(2) lcolor(black) lp(dash) /// 
lw(thick)), /// 
ytitle("Unemployment rate", size(small)) /// 
 yscale(nofextend) ///
ttitle("") ylabel(minmax 8 12, labgap(medsmall) /// 
labsize(small)) /// 
ylabel(minmax 25 35, axis(2) labsize(small)) /// 
ytitle("FF popularity", axis(2) size(small)) ///
 tscale(nofextend) /// 
graphregion(fcolor(white) lcolor(white)) legend(off) /// 
tline( 2007m5 2008m9 2010m9, lwidth(vthin) lc(black)) ///
tlabel(minmax 2007m5 2008m9 2010m9, labsize(small) /// 
angle(45)) yscale(nofextend axis(2))


graph save "unemp", replace


twoway (line infl ym, sort lcolor(black) lw(thick)) /// 
(line iff ym, sort yaxis(2) lcolor(black) lp(dash) /// 
lw(thick)), /// 
ytitle("Inflation" "% change, 12 months", /// 
 size(small)) /// 
yscale(nofextend) ///
ttitle("") ylabel(minmax 0 , labgap(medsmall) /// 
labsize(small)) /// 
ylabel(minmax 25 35, axis(2) labsize(small)) /// 
ytitle("FF popularity", axis(2)  /// 
size(small)) ///
 tscale(nofextend) /// 
graphregion(fcolor(white) lcolor(white)) legend(off) /// 
tline( 2007m5 2008m9 2010m9, lwidth(vthin) lc(black)) ///
tlabel(minmax 2007m5 2008m9 2010m9, labsize(small) /// 
angle(45)) yscale(nofextend axis(2))

graph save "infl", replace


twoway (line iip ym, sort lcolor(black) lw(thick)) /// 
(line iff ym, sort yaxis(2) lcolor(black) /// 
lp(dash) lw(thick)), /// 
ytitle("Index of industrial production" /// 
"% change, 12 months", /// 
size(small)) yscale(nofextend) ///
ttitle("") ylabel(minmax -10 0 10, format(%12.0f) /// 
labgap(medsmall) labsize(small)) /// 
ylabel(minmax 25 35, axis(2) labsize(small)) /// 
ytitle("FF popularity", axis(2) ///
 size(small)) ///
 tscale(nofextend) /// 
graphregion(fcolor(white) lcolor(white)) legend(off) /// 
tline( 2007m5 2008m9 2010m9, lwidth(vthin) lc(black)) ///
tlabel(minmax 2007m5 2008m9 2010m9, labsize(small) /// 
angle(45)) yscale(nofextend axis(2)) 

graph save "iip", replace


graph combine "infl" "unemp" "iip" "i_cci", /// 
cols(2) graphregion(fcolor(white) lcolor(white)) /// 
xcommon graphregion(margin(t+3))

graph save "Figure3", replace

